<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>



    <!--{include file='comm/header.tpl'}-->
    <title>下午茶套餐信息配置</title>
    <!--{include file='comm/comm_cal.tpl'}-->
    <!--{include file='comm/comm_editor.tpl'}-->
    <!--引用div做成的下拉框效果样式-->
    <link rel="stylesheet" href="/quanliadmin/docroot/css/department_select.css" type="text/css" media="screen" />

    <!--引用div做成的下拉框效果js-->
    <script language="JavaScript" src="/quanliadmin/docroot/js/department_select.js" type="text/javascript"></script>
</head>

<body>

<style>
    .imageSites{
        position: absolute;
        left:275px;
        top:8px;
    }
    .search_option_drop{
        width:300px;
    }

</style>

<div class="container">

    <div class="comm_content">
            <div class="search-box">
                <div style="position:relative">
                    <form class="form-inline" id="search_form" onsubmit="return false;">
                            <span>
                               套餐名称：<input type="text"  class="form-control input-sm" name="package_name" id="package_name" style="width:150px;"/>
                            </span>
                            <span>
                                <button type="button" class="btn btn-primary" id="searchBtn" onclick="basicSetting.search();">查询</button>
                            </span>
                            <span>
                                <button type="button" class="btn btn-warning" id="clearBtn" onclick="basicSetting.clearUp();" >重置</button>
                            </span>
                    </form>
                </div>
            </div>
            <div id="pop" style="display: none;">
                <form id="categoryForm" class="form-horizontal" role="form" onsubmit="return false;">
                    <input type="hidden" id="itemCategoryID" name="itemCategoryID" value=""/>
                    <div class="form-group">
                        <label for="itemCategoryName" class="col-sm-3 control-label">套餐名称：</label>
                        <input type="hidden" name="package_id" id="package_id" value="">
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="packageName" name="packageName" placeholder="请输入套餐名称" style="width: 350px"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="itemCategoryName" class="col-sm-3 control-label">蛋糕信息：</label>
                        <div class="col-sm-9">
                            <select class="form-control w150" id="cakeName" name="cakeName" size="1" style="width:150px;">
                                <option value="">请选择</option>

                                <!--{foreach from=$cakeInfo item=pic key=k}-->
                                <option value="<!--{$pic->product_code}-->"><!--{$pic->goodsName}--></option>
                                <!--{/foreach}-->

                            </select>

                        </div>
                    </div>
                    <div class="form-group">
                        <label for="itemCategoryName" class="col-sm-3 control-label">咖啡信息：</label>
                        <div class="col-sm-9">
                            <select class="form-control w150" id="coffeeName" name="coffeeName" size="1" style="width:150px;">
                                <option value="">请选择</option>

                                <!--{foreach from=$coffeeInfo item=pic key=k}-->
                                <option value="<!--{$pic->product_code}-->"><!--{$pic->goodsName}--></option>
                                <!--{/foreach}-->

                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="itemCategoryName" class="col-sm-3 control-label">价格：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="package_price" name="package_price" onkeyup="value=value.replace(/[^\d.]/g,'')" style="width: 150px"/>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="itemCategoryName" class="col-sm-3 control-label">蛋糕图片：</label>
                        <div class="col-sm-9">
                            <button type="button" class="btn btn-default" id="update_logo">点击上传图片</button>
                            <div id="logo_img_box" style="display: none;margin-top: 5px;"></div>
                            <input type="hidden" name="itemName" id="itemName" value="" />

                        </div>
                    </div>

                    <div class="form-group">
                        <label for="itemCategoryName" class="col-sm-3 control-label">咖啡图片：</label>
                        <div class="col-sm-9">
                            <button type="button" class="btn btn-default" id="update_logo_3">点击上传图片</button>
                            <div id="logo_img_box_3" style="display: none;margin-top: 5px;"></div>
                            <input type="hidden" name="itemName_3" id="itemName_3" value="" />

                        </div>
                    </div>

                    <div class="form-group">
                        <label for="itemCategoryName" class="col-sm-3 control-label">缩略图片：</label>
                        <div class="col-sm-9">
                            <button type="button" class="btn btn-default" id="update_logo_2">点击上传图片</button>
                            <div id="logo_img_box_2" style="display: none;margin-top: 5px;"></div>
                            <input type="hidden" name="itemName_2" id="itemName_2" value="" />

                        </div>
                    </div>

                    <div class="form-group">
                        <label for="itemCategoryName" class="col-sm-3 control-label">蛋糕信息：</label>
                        <div class="col-sm-9">
                          <textarea rows="350px" cols="350px" id='package_remark'name="package_remark"></textarea>

                        </div>
                    </div>

                    <div class="form-group">
                        <label for="itemCategoryName" class="col-sm-3 control-label">咖啡信息：</label>
                        <div class="col-sm-9">
                            <textarea rows="350px" cols="350px" id='package_remark_2'name="package_remark_2"></textarea>

                        </div>
                    </div>


                </form>
            </div>
            <table id="flex" style="display:none"></table>
        </div>
    
</div>
<script type="text/javascript">
$("#flex").flexigrid({
    url:"/invokingAjax-backend/dunch/dunch.ajax?operFlg=2",
    dataType: "json",
    colModel : [

        {display: "操作", width : 100, align: "center"},
        {display: "套餐ID", width : 100, align: "center"},
        {display: "套餐名称", width : 140,align:"left"},
        {display: "套餐价格", width : 140,align:"left"},
        {display: "蛋糕信息", width : 240,align:"left"},
        {display: "咖啡信息", width : 240,align:"left"}

    ],
    buttons : [
        {name: "添加", bclass: "add", onpress : "basicSetting.add"}
    ],
    sortname: "createTime",
    sortorder: "desc",
    usepager: true,
    rp: 10,
    useRp: true,
    showTableToggleBtn: true,
    onSubmit: function() {
        var dt = $('#search_form').serializeArray();
        $("#flex").flexOptions({params: dt});
        return true;
    }
});

var basicSetting = {

    itemCategoryID:'',
    itemID:'',
    selected:'',
    //搜索
    search: function() {
        var dt = $('#search_form').serializeArray();
        $("#flex").flexOptions({params: dt}).flexReload();
    },
    //添加分类信息
    add: function() {
        E.popup.open({
            id:"pop",                  //获取id为"pop"元素内的HTML
            title:"添加套餐配置信息",       //弹出层标题
            css: "width:550px;hight:550px;",   //设置弹出层样式
            btnName: "保存",        //执行“确定”操作的按钮名称
            btnCall:"basicSetting.checkInfo();"  //点击确定后执行的方法
        });
    },
    //验证分类信息
    checkInfo:function(){
        var data = E.getFormValues("categoryForm");
        var error_msg = "";

        if (data.packageName == ''){
            error_msg += '套餐名称不能为空<br/>';
        }

        if (data.packageName == ''){
            error_msg += '蛋糕信息名称不能为空<br/>';
        }
        if (data.coffeeName == ''){
            error_msg += '咖啡信息名称不能为空<br/>';
        }
        if (data.package_price == ''){
            error_msg += '价格不能为空<br/>';
        }
        if (data.itemName == ''){
            error_msg += '蛋糕图片不能为空<br/>';
        }
       // if (data.itemName_2 == ''){
        //    error_msg += '缩略图片不能为空<br/>';
      //  }
        if (data.itemName_3 == ''){
            error_msg += '咖啡图片不能为空<br/>';
        }

        if (data.package_remark == ''){
            error_msg += '蛋糕信息不能为空<br/>';
        }

        if (data.package_remark_2 == ''){
            error_msg += '咖啡信息不能为空<br/>';
        }

        if (error_msg != ""){
            E.alert(error_msg);
       }else{
            E.confirm('您确认添加分类吗?', "basicSetting.addExe");
       }
    },
    //执行 添加
    addExe: function() {
        //弹出遮罩层
        E.loadding.open("执行中……");
        //获取表单参数
        var data = E.getFormValues('categoryForm');
        jquery_ajax(1,data,basicSetting.callback);
        //关闭弹出层
        E.popup.close();
        //关闭遮罩层
        E.loadding.close();
    },
    /**
     * 编辑分类
     */
    edit: function( package_id ) {
        E.loadding.open("正在查询，请稍后...");
        E.ajax_post({
            url:"/invokingAjax-backend/dunch/dunch.ajax?operFlg=3",
            data:{package_id:package_id},
            call:"basicSetting.editResult"
        });
        //显示弹出层
        E.popup.open({
            id:"pop",
            title: "修改分类",
            css: "width:550px;",
            btnName: "确认修改",
            btnCall:"basicSetting.editCheck();"
        });
    },
    //查询结果
    editResult:function(o){
        E.loadding.close();
        if( o.code != 200 ){
            E.alert( o.message );
            return false;
        }
        var data = o.data;
        $('#packageName').val(data.package_name);
        $('#package_id').val(data.package_id);
        $("#cakeName").val(data.cake);
        $("#coffeeName").val(data.coffee);
        $('#itemName').val(data.package_image);
        $('#itemName_2').val(data.package_image_2);
        $('#itemName_3').val(data.package_image_3);
        $('#package_price').val(data.package_price);
        $('#package_remark').val(data.package_remark);
        $('#package_remark_2').val(data.package_remark_2);
    },
    //修改验证
    editCheck:function(){
        var data = E.getFormValues("categoryForm");
        var error_msg = '';
        if (data.packageName == ''){
            error_msg += '套餐名称不能为空<br/>';
        }

        if (data.packageName == ''){
            error_msg += '蛋糕信息名称不能为空<br/>';
        }
        if (data.coffeeName == ''){
            error_msg += '咖啡信息名称不能为空<br/>';
        }
        if (data.package_price == ''){
            error_msg += '价格不能为空<br/>';
        }
        if (data.itemName == ''){
            error_msg += '蛋糕图片不能为空<br/>';
        }
        //if (data.itemName_2 == ''){
         //   error_msg += '图片不能为空<br/>';
       // }
        if (data.itemName_3 == ''){
            error_msg += '咖啡图片不能为空<br/>';
        }
        if (data.package_remark == ''){
            error_msg += '蛋糕信息不能为空<br/>';
        }

        if (data.package_remark_2 == ''){
            error_msg += '咖啡信息不能为空<br/>';
        }

        if (error_msg != ""){
            E.alert(error_msg);
        }else{
            E.confirm('您确认修改分类吗?', "basicSetting.editExe");
        }

    },
    //编辑执行
    editExe:function(){
        //弹出遮罩层
        E.loadding.open("正在执行，请稍后...");
        //获取表单参数
        var data = E.getFormValues('categoryForm');
        jquery_ajax(4,data,basicSetting.callback);
        //关闭弹出层
        E.popup.close();
        //关闭遮罩层
        E.loadding.close();
    },


    //删除选项分类
    delPackge:function( package_id ){
        //this.selected = $( thisObj ).parents("tr");
        this.package_id = package_id;
        E.confirm('您确认删除该分类选项吗?','basicSetting.delExe');
    },

    delExe:function(){
        $.ajax({
            type: "POST",
            url: "/invokingAjax-backend/dunch/dunch.ajax?operFlg=5",
            dataType: "JSON",
            data:{
                package_id: this.package_id
            },
            success: function(result_obj){
                if (result_obj.code == 200) {
                    E.alert(result_obj.message, 2);
                  $("#flex").flexReload();

                }
                else {
                    E.alert(result_obj.message);
                }
            }
        });
    },

    //回调函数
    callback: function( obj ) {
        E.loadding.close();
        E.popup.close();
        if( obj.code == 200 ){
            E.alert( obj.message , 2 , 'basicSetting.load');
        }else{
            E.alert(obj.message);
        }
    },
    load: function() {
        $("#flex").flexReload();
    },
    //重置分类名称
    clearUp:function() {
        $("#package_name").val('');
        basicSetting.load();
    }
};
function jquery_ajax(flg,data,func){
    $.ajax({
        type: "post",
        url: "/invokingAjax-backend/dunch/dunch.ajax?operFlg="+flg,
        dataType: "json",
        data: data,
        success: function( result_obj ) {
            func(result_obj);
        },
        error : function(msg){
            alert('网络不给力，请重新尝试...');
        }
    });
}


//绑定上传图片
KindEditor.ready(function(K) {

    var kindEditor_upload = K.editor({
        allowFileManager : true,
        uploadJson: '/framework/kindeditor/php/upload_json.php?act=system'
    });

    $(document).on('click', '#update_logo', function() {

        kindEditor_upload.loadPlugin('image', function() {
            kindEditor_upload.plugin.imageDialog({
                showRemote : false,
                clickFn : function(url) {

                    $('#logo_img_box').html('<img style="width:110px;height: 110px;" src="' + url + '"> <a href="javascript: void(0);" id="del_log_img">删除</a>').show();
                    $('#itemName').val(url);
                    kindEditor_upload.hideDialog();

                }
            });
        });

    });

    $(document).on('click', '#update_logo_2', function() {

        kindEditor_upload.loadPlugin('image', function() {
            kindEditor_upload.plugin.imageDialog({
                showRemote : false,
                clickFn : function(url) {

                    $('#logo_img_box_2').html('<img style="width:110px;height: 110px;" src="' + url + '"> <a href="javascript: void(0);" id="del_log_img_2">删除</a>').show();
                    $('#itemName_2').val(url);
                    kindEditor_upload.hideDialog();

                }
            });
        });

    });


    $(document).on('click', '#update_logo_3', function() {

        kindEditor_upload.loadPlugin('image', function() {
            kindEditor_upload.plugin.imageDialog({
                showRemote : false,
                clickFn : function(url) {

                    $('#logo_img_box_3').html('<img style="width:110px;height: 110px;" src="' + url + '"> <a href="javascript: void(0);" id="del_log_img_3">删除</a>').show();
                    $('#itemName_3').val(url);
                    kindEditor_upload.hideDialog();

                }
            });
        });

    });

    $(document).on('click', '#del_log_img', function() {
        $('#logo_img_box').html('').hide();
        $('#itemName').val('');
    });

    $(document).on('click', '#del_log_img_2', function() {
        $('#logo_img_box_2').html('').hide();
        $('#itemName_2').val('');
    });
    $(document).on('click', '#del_log_img_3', function() {
        $('#logo_img_box_3').html('').hide();
        $('#itemName_3').val('');
    });
});

</script>
</body>
</html>